package com.lvwenguo.controller;

import com.lvwenguo.model.ProductList;
import com.lvwenguo.service.ServiceInter;
import com.lvwenguo.service.serviceImple.ServiceImple;
import com.lvwenguo.utils.PageUtlis;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "IndexProductListServlet",urlPatterns = "/IndexProductListServlet/product/product_list")
public class IndexProductListServlet extends  HttpServlet  {
ServiceInter serviceImpol =new ServiceImple();
    private PageUtlis<ProductList> pageUtlis=new PageUtlis<ProductList>(9);
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //域存入数据
        List<ProductList> lists = serviceImpol.selectProductList();
        //前端传过来得页数
        String page = req.getParameter("page");
        //初始化为1
        req.setAttribute("productList", pageUtlis.Pagination(lists,Integer.parseInt( page)));
        //返回页数（总数）
        req.setAttribute("page",pageUtlis.NumberPages(lists));
        req.getRequestDispatcher("/view/product/product_list.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }

}
